<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Admin\Protype;
use DB;

class IndexController extends Controller
{
    //后台框架页
    public function index(){
        //获取顶级分类
        $protype = Protype::select('id','protype_name') -> orderBy('id','asc') -> get();
    	return view('admin.index.index',['protype' => $protype]);
    }

    //后台欢迎页
    public function welcome(){
        $statistics = $this -> statisticsTotal();
        $data['HTTP_HOST'] = $_SERVER['HTTP_HOST'];
        $data['SERVER_ADDR'] = $_SERVER['SERVER_ADDR'];
        //$data['SERVER_ADDR'] = GetHostByName($_SERVER['SERVER_NAME']);
        $data['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
        $data['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
        $data['SERVER_SOFTWARE'] = $_SERVER['SERVER_SOFTWARE'];
//        $data['CONTEXT_DOCUMENT_ROOT'] = $_SERVER['CONTEXT_DOCUMENT_ROOT'];
//        $data['SYSTEMROOT'] = $_SERVER['SYSTEMROOT'];
        $data['MAX_EXEC_TIME'] = get_cfg_var("max_execution_time").'秒';
        //$data['MAX_EXEC_TIME'] = ini_get("max_execution_time").'秒';//获取php.ini中配置项的值
        $data['PHP_OS']   = php_uname();
        $data['LANG'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
        $data['NOW_TIME'] = date('Y-m-d H:i:s',time());
        $data['HTTP_USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
        $arRuntime =explode(",", exec('uptime'));
        $data['RUNTIME'] = $arRuntime[0];
        exec("wmic LOGICALDISK get name",$dirs);
        $data['DIRS'] = implode('\\',$dirs);
        //$data['CPU_COUNT'] = $_SERVER['PROCESSOR_IDENTIFIER'];
        session_start();
        $data['SESSION_COUNT'] = count($_SESSION);
        $data['SESSION_ID'] = session_id();

        //echo '<pre>';
        //var_dump($_SERVER);die;
    	return view('admin.index.welcome',['data' => $data, 'statistics' => $statistics]);
    }

    public function statisticsTotal(){
        $statistics = array(
            'protype' => array(
                'count'       => $this -> statistics('protype','created_at','count'),
                'today'       => $this -> statistics('protype','created_at','today'),
                'yesterday'   => $this -> statistics('protype','created_at','yesterday'),
                'week'        => $this -> statistics('protype','created_at','week'),
                'lastweek'    => $this -> statistics('protype','created_at','lastweek'),
                'month'       => $this -> statistics('protype','created_at','month'),
                'lastmonth'   => $this -> statistics('protype','created_at','lastmonth'),
                'quarter'     => $this -> statistics('protype','created_at','quarter'),
                'lastquarter' => $this -> statistics('protype','created_at','lastquarter'),
            ),
            'profession' => array(
                'count'       => $this -> statistics('profession','created_at','count'),
                'today'       => $this -> statistics('profession','created_at','today'),
                'yesterday'   => $this -> statistics('profession','created_at','yesterday'),
                'week'        => $this -> statistics('profession','created_at','week'),
                'lastweek'    => $this -> statistics('profession','created_at','lastweek'),
                'month'       => $this -> statistics('profession','created_at','month'),
                'lastmonth'   => $this -> statistics('profession','created_at','lastmonth'),
                'quarter'     => $this -> statistics('profession','created_at','quarter'),
                'lastquarter' => $this -> statistics('profession','created_at','lastquarter'),
            ),
            'course' => array(
                'count'       => $this -> statistics('course','created_at','count'),
                'today'       => $this -> statistics('course','created_at','today'),
                'yesterday'   => $this -> statistics('course','created_at','yesterday'),
                'week'        => $this -> statistics('course','created_at','week'),
                'lastweek'    => $this -> statistics('course','created_at','lastweek'),
                'month'       => $this -> statistics('course','created_at','month'),
                'lastmonth'   => $this -> statistics('course','created_at','lastmonth'),
                'quarter'     => $this -> statistics('course','created_at','quarter'),
                'lastquarter' => $this -> statistics('course','created_at','lastquarter'),
            ),
            'lession' => array(
                'count'       => $this -> statistics('lession','created_at','count'),
                'today'       => $this -> statistics('lession','created_at','today'),
                'yesterday'   => $this -> statistics('lession','created_at','yesterday'),
                'week'        => $this -> statistics('lession','created_at','week'),
                'lastweek'    => $this -> statistics('lession','created_at','lastweek'),
                'month'       => $this -> statistics('lession','created_at','month'),
                'lastmonth'   => $this -> statistics('lession','created_at','lastmonth'),
                'quarter'     => $this -> statistics('lession','created_at','quarter'),
                'lastquarter' => $this -> statistics('lession','created_at','lastquarter'),
            ),
            'member' => array(
                'count'       => $this -> statistics('member','created_at','count'),
                'today'       => $this -> statistics('member','created_at','today'),
                'yesterday'   => $this -> statistics('member','created_at','yesterday'),
                'week'        => $this -> statistics('member','created_at','week'),
                'lastweek'    => $this -> statistics('member','created_at','lastweek'),
                'month'       => $this -> statistics('member','created_at','month'),
                'lastmonth'   => $this -> statistics('member','created_at','lastmonth'),
                'quarter'     => $this -> statistics('member','created_at','quarter'),
                'lastquarter' => $this -> statistics('member','created_at','lastquarter'),
            ),
        );
        return $statistics;
    }

}
